package com.hafu.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @Author:xiaohai 2072158919@qq.com 海航源
 * @Date: 2024/11/1  下午3:14
 * @Version 1.0
 * @description
 */
public class DbUtil {
    private static final String URL = "jdbc:mysql://117.72.41.133:13306/db_jxcms1?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC&useSSL=true";
    private static final String USER = "root";
    private static final String PASSWORD = "123456";

    public static Connection getConnection() throws SQLException {
        Connection connection = DriverManager.getConnection(URL, USER, PASSWORD);
        System.out.println("数据库连接成功");
        return connection;
    }

    public static void closeConnection(Connection connection) throws SQLException {
        if (connection != null) {
            connection.close();
        }
    }

    public static void main(String[] args) throws SQLException {
        System.out.println(DbUtil.getConnection());
    }
}


